package kuzmenkov.oip.controller;

import kuzmenkov.oip.service.ImageProcessingService;
import kuzmenkov.oip.service.impl.ParameterItem;
import org.springframework.web.jsf.FacesContextUtils;

import javax.faces.context.FacesContext;
import java.util.List;
import java.util.logging.Logger;

/**
 * Class is responsible for interacting with user. It helps to process images
 * It's a backing bean for a image processing page
 * User: Michael Kuzmenkov
 * Date: 16.03.2009
 * Time: 1:35:53
 */
public class ImagingController extends ErrorSupport {

    private Logger log = Logger.getLogger("global");

    private ImageProcessingService service;

    public ImagingController() {
        try {
            service = (ImageProcessingService) FacesContextUtils.
                    getWebApplicationContext(FacesContext.getCurrentInstance()).
                    getBean("imageProcessingService");
        } catch (Exception e) {
            addError(e);
        }

    }


    public String getAdapterReference () {
        String ref =null;
        try {
            String clazz = service.getModuleAdapterClass();
            ref="../adapters/"+clazz.replace('.','/')+".java";
        } catch (Exception e){
            addError(e);
        }
        return  ref;
    }

    public String getModuleName() {
        String n = null;
        try {
            n = service.getModuleName();
        } catch (Exception e) {
            addError(e);
        }
        return n;
    }

    public String getModuleProducerName() {
        String n = null;
        try {
            n = service.getModuleProducerName();
        } catch (Exception e) {
            addError(e);
        }
        return n;
    }

    public String getAppletWidth() {
        String w = "700";
        try {
            w = "" + service.getPanelWidth();
        } catch (Exception e) {
            addError(e);
        }
        return w;
    }

    public String getAppletHeight() {
        String h = "500";
        try {
            h = "" + service.getPanelHeight();
        } catch (Exception e) {
            addError(e);
        }
        return h;
    }

    public List<ParameterItem> getParameters () {
        List<ParameterItem>  params = null;
        try {
            params = service.getParameterItems();
        } catch (Exception e) {
            addError(e);
        }
        return params;
    }


}
